package org.groupg.practice.guiPractice.tools;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class CustomComponentExample extends JPanel {
    private Color circleColor = Color.RED;
    private String message = "点击我!";

    public CustomComponentExample() {
        setPreferredSize(new Dimension(300, 300));
        setBackground(Color.WHITE);

        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                circleColor = new Color(
                        (float) Math.random(),
                        (float) Math.random(),
                        (float) Math.random()
                );
                message = "点击位置: (" + e.getX() + ", " + e.getY() + ")";
                repaint(); // 重绘组件
            }
        });
    }
}


